package com.example.ArrayList;

import java.util.Iterator;
import java.util.LinkedList;

public class Test1LinkedList {
    public static void main(String[] args) {
        //method1();
        //method2();


    }

    private static void method2() {
        LinkedList<String> list = new LinkedList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");

        list.addFirst("qqq");
        System.out.println(list);   //[qqq, aaa, bbb, ccc]
        list.addLast("www");
        System.out.println(list);   //[qqq, aaa, bbb, ccc, www]

        String first = list.getFirst();
        System.out.println(first);  //qqq
        String last = list.getLast();
        System.out.println(last);   //www

        String removeFirst = list.removeFirst();
        System.out.println(removeFirst);    //qqq
        String removedLast = list.removeLast();
        System.out.println(removedLast);    //www
        System.out.println(list);   //[aaa, bbb, ccc]
    }

    private static void method1() {
        LinkedList<String> list = new LinkedList<>();
        list.add("a");
        list.add("b");
        list.add("c");

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        System.out.println("-------------------");

        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }

        System.out.println("-------------------");

        for (String s : list) {
            System.out.println(s);
        }
    }
}
